﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Timers;
using System.Windows.Forms;
using System.Net.Sockets;

namespace Goa
{
    class Excercise
    {
        private int tickcounter;
        public System.Timers.Timer testTimer = new System.Timers.Timer();
        private int powerValue;
        MultiServer server;
        TcpClient client;

        public Excercise(MultiServer s,  TcpClient c)
        {
            server = s;
            client = c;
            tickcounter = 0;
            powerValue = 50;
        }

        public void InspanningsTest()
        {
            server.SendMessage(client, "PW " + powerValue);
            testTimer.Interval = 100;
            testTimer.Elapsed += new ElapsedEventHandler(TimerTickEvent);
            testTimer.Start();
        }

        public void TimerTickEvent(object source, ElapsedEventArgs e)
        {
            
            if ((tickcounter % 300) == 0)
            {
                //if (setHeartrate(heartRate) < 60)
                //{
                //    MessageBox.Show("Warning: Heartrate too low");
                //}
                //else if (setHeartrate(heartRate) > 200)
                //{
                //    MessageBox.Show("Warning: Heartrate too high");
                //}
                if (tickcounter < 3000)
                {
                    powerValue = powerValue + 15;
                    server.SendMessage(client, "PW " + powerValue);
                }
                else if (tickcounter == 3000)
                {
                    powerValue = powerValue + 5;
                    server.SendMessage(client, "PW " + powerValue);
                }
                else if (tickcounter == 6000)
                {
                    powerValue = powerValue - 15;
                    server.SendMessage(client, "PW " + powerValue);
                }
                else if (tickcounter == 7200)
                {
                    testTimer.Stop();
                }
            }
            else
            {
                server.SendMessage(client, "st");
            }
            tickcounter++;
            Console.WriteLine(tickcounter);
        }
    }
}
